class Faquestion < ActiveRecord::Base
  has_many :faquestions_faq_categories
  has_many :faq_categories, :through => :faquestions_faq_categories
  
  def category_ids
    faquestions_faq_categories.collect{|e| e.faq_category_id }
  end
  
  def add_categories(category_ids)
    category_ids.each do |id|
      category = FaqCategory.find_by_id(id)
      next unless category 
      self.faq_categories << category
    end
  end
  
  def clear_up_categories
    self.faq_categories = []
    save!
  end
end
